package com.xyzwps.example.stream;

import java.util.Collection;
import java.util.Iterator;
import java.util.Objects;

public class CollectionStream<T> extends Stream<T> {

    private final Iterator<T> iterator;

    public CollectionStream(Collection<T> collection) {
        this.iterator = Objects.requireNonNull(collection).iterator();
    }

    @Override
    public Parcel<T> next() {
        if (iterator.hasNext()) {
            return Parcel.deliver(iterator.next());
        } else {
            return Parcel.done();
        }
    }
}
